package com.jwiki.app.jkeeper;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.context.annotation.Bean;

import com.google.code.kaptcha.Constants;
import com.google.code.kaptcha.servlet.KaptchaServlet;

@SpringBootApplication
public class JKeeperApplication extends SpringBootServletInitializer {

    public static void main(String[] args) {
        SpringApplication.run(JKeeperApplication.class, args);
    }

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
        return builder.sources(JKeeperApplication.class);
    }

    @Bean
    public ServletRegistrationBean servletRegistration() {
        ServletRegistrationBean registry = new ServletRegistrationBean(new KaptchaServlet());
        registry.addInitParameter(Constants.KAPTCHA_SESSION_CONFIG_KEY, "KaptchaKey");
        registry.addInitParameter(Constants.KAPTCHA_BORDER, "no");
        registry.addInitParameter(Constants.KAPTCHA_TEXTPRODUCER_FONT_SIZE, "30");
        registry.addInitParameter(Constants.KAPTCHA_IMAGE_HEIGHT, "40");
        registry.addInitParameter(Constants.KAPTCHA_IMAGE_WIDTH, "160");
        registry.addUrlMappings("/kaptcha.jpg");
        return registry;
    }

}
